//
//  Common.m
//  AiShangJinFuSalesman
//
//  Created by AiShangTong on 2017/6/5.
//  Copyright © 2018年 AiShangTong. All rights reserved.
//

#import "Common.h"
#import <objc/runtime.h>

NSString *const Enumeration_ID_TYPE = @"ID_TYPE";//证件类型
NSString *const Enumeration_political = @"political";//政治面貌
NSString *const Enumeration_household = @"household";//户口性质
NSString *const Enumeration_marriStatus = @"marriStatus";//婚姻状况
NSString *const Enumeration_jobStatus = @"jobStatus";//在职状态
NSString *const Enumeration_nation = @"nation";//民族
NSString *const Enumeration_education = @"education";//学历
NSString *const Enumeration_sex = @"sex";//性别


NSString *const ASJFMyUserLoginTokenKey = @"ASJFMyUserLoginTokenKey";
NSString *const ASJFMyUserInfoAccountKey = @"ASJFMyUserInfoAccountKey";
NSString *const ASJFUserNameKey = @"ASJFUserNameKey";


@implementation Common

+ (UIColor*) hexColor:(NSInteger)hexValue {
    
    CGFloat red = (CGFloat)((hexValue & 0xFF0000) >> 16) / 255.0;
    CGFloat green = (CGFloat)((hexValue & 0xFF00) >> 8) /255.0;
    CGFloat blue = (CGFloat)(hexValue & 0xFF) / 255.0;
    UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:1];
    return color;
}

+(CGRect)screenBounds {
    return [[UIScreen mainScreen] bounds];
}

+(UIImage*) imageWithFrame:(CGRect)frame color:(UIColor*)color {
    if(CGRectEqualToRect(frame, CGRectZero)) {
        frame = CGRectMake(0, 0, 1, 1);
    }
    UIGraphicsBeginImageContext(frame.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, color.CGColor);
    CGContextFillRect(context, frame);
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

+(UIFont*)systemFontOfSize:(CGFloat)size {
    
    return [UIFont systemFontOfSize:size];
}

+(UIFont*)boldSystemFontOfSize:(CGFloat)size {
    return [UIFont boldSystemFontOfSize:size];
}

+(BOOL)isVariableWithClass:(Class)cls varName:(NSString *)name {
    unsigned int outCount, i;
    Ivar *ivars = class_copyIvarList(cls, &outCount);
    for (i = 0; i < outCount; i++) {
        Ivar property = ivars[i];
        NSString *keyName = [NSString stringWithCString:ivar_getName(property) encoding:NSUTF8StringEncoding];
        keyName = [keyName stringByReplacingOccurrencesOfString:@"_" withString:@""];
        if ([keyName isEqualToString:name]) {
            return YES;
        }
    }
    return NO;
}

+ (NSString *)ServicesURL:(NSString *)url
{
    NSString *servicesURL = ApplicationEnvironmentProduction ? @"http://52.80.164.199:8096" : @"http://52.80.164.199:8096";
    NSString *URLString = [NSString stringWithFormat:@"%@/%@", servicesURL, url];
    return URLString;
}
 
+(BOOL)loginState{
  NSString *str =  [AD_UserDefaults objectForKey:ASJFMyUserLoginTokenKey];
    if (str.length) {
        return YES;
    }else{
        return NO;
    }
}

+(BOOL)checkNetWork{
//    NSInteger numbe = [RequestManager reachabilityStatus];
//    NSLog(@"网络状态-----%ld",(long)numbe);
//    if ([RequestManager reachabilityStatus] == AFNetworkReachabilityStatusReachableViaWiFi ) {
//        return YES;
//    }else if ([RequestManager reachabilityStatus] == RequestReachabilityStatusReachableViaWWAN){
//        return YES;
//    }else if ([RequestManager reachabilityStatus] == RequestReachabilityStatusNotReachable){
//        return NO;
//    }else{
        return NO;
//    }
    
}
@end
